import { forBindEventThis } from '../../../../direct/Func/eventBind';
import { settimeNth } from '../../../../Func/uniFunc/Func';
import { event_check_operate } from '../../../Event/Func/event_check/Classes/cla_event_check_operate';
import { special_keyVal } from '../DataDefine/sourceData';
import { select_node_dataMana } from './cla_select_node_dataMana';

const select_node_operateTag = 'select_node_operate';

const event_check_func = new event_check_operate();

class select_node_operate extends select_node_dataMana {
  get [Symbol.toStringTag]() {
    return select_node_operateTag;
  }

  /**
   * @type {{id:string}} props
   */
  constructor(props) {
    super(props);
    forBindEventThis(this, 'eventBind');

    this.eventM.addEventListen(
      this.select_node_border_dom,
      'click',
      this.eventBind.select_node_border_dom_click
    );

    this.eventM.addEventListen(
      this.select_node_content_uni_items_border_dom,
      'click',
      this.eventBind.uni_container_child_dom_left_click
    );

    this.eventM.addEventListen(
      this.select_node_content_uni_items_border_dom,
      'dblclick',
      this.eventBind.uni_container_child_dom_left_DBClick_quick_certain
    );

    this.eventM.addEventListen(
      this.select_node_content_btn_dom,
      'click',
      this.eventBind.uni_content_btn_left_click
    );

    this.eventM.addEventListen(
      this.focusDisplay_el,
      'click',
      this.eventBind.focusDisplay_white_space_click
    );

    this.eventM.addEventListen(
      this.select_node_quick_func_select_all_node,
      'click',
      this.eventBind.quick_func_select_all_click
    );

    this.eventM.addEventListen(
      this.select_node_quick_func_restart_select_node,
      'click',
      this.eventBind.quick_func_restart_select_click
    );
  }

  /**
   * 元素 点击 展开 浮动元素 选择器
   * @param {MouseEvent} event
   */
  select_node_border_dom_click(event) {
    if (!event_check_func.cur_event(event).left_click().checked_result) {
      return;
    }

    this.open_focusDisplay_func();
  }

  /**
   * uni item 元素 单击 选项
   * @param {MouseEvent} event
   */
  uni_container_child_dom_left_click(event) {
    // if (!specialKey_check(event)) {
    //   return;
    // }
    // if (!mouse_leftbotton(event)) {
    //   return;
    // }

    if (
      !event_check_func.cur_event(event).specialKey_before_check().left_click()
        .checked_result
    ) {
      return;
    }

    let keyVal_node = this.get_uni_keyVal_node(event.target);

    if (keyVal_node == null) {
      return;
    }

    let keyVal = keyVal_node.getAttribute(special_keyVal);

    this.dis_or_active_keyVal_node_func(keyVal);
  }

  /**
   * uni item 元素 双击 快速 确认
   * @param {MouseEvent} event
   */
  uni_container_child_dom_left_DBClick_quick_certain(event) {
    // if (!specialKey_check(event)) {
    //   return;
    // }
    // if (!mouse_leftbotton(event)) {
    //   return;
    // }

    if (
      !event_check_func.cur_event(event).left_click().specialKey_before_check()
        .checked_result
    ) {
      return;
    }

    let keyVal_node = this.get_uni_keyVal_node(event.target);

    if (keyVal_node == null) {
      return;
    }

    let keyVal = keyVal_node.getAttribute(special_keyVal);

    this.active_keyVal_node_func(keyVal);

    /**
     * 逻辑修订
     * 在 快速 选择动画 结束后 在进行 确认修改
     */
    settimeNth(200, () => {
      this.certain_func();
    });
  }

  /**
   * uni item 元素 确认按钮
   * @param {MouseEvent} event
   */
  uni_content_btn_left_click(event) {
    // if (!specialKey_check(event)) {
    //   return;
    // }
    // if (!mouse_leftbotton(event)) {
    //   return;
    // }
    // if (!is_itself_event(event)) {
    //   return;
    // }

    if (
      !event_check_func
        .cur_event(event)
        .is_itself()
        .specialKey_before_check()
        .left_click().checked_result
    ) {
      return;
    }

    this.certain_func();
  }

  /**
   * 焦点元素 空白处 点击 取消 当前 展示
   * @param {MouseEvent} event
   */
  focusDisplay_white_space_click(event) {
    if (!event_check_func.cur_event(event).is_itself().checked_result) {
      return;
    }

    this.cancel_func();
  }

  /**
   * 左键 单击 重选
   * @param {MouseEvent} event
   * @returns
   */
  quick_func_restart_select_click(event) {
    if (
      !event_check_func.cur_event(event).left_click().is_itself().checked_result
    ) {
      return;
    }

    this.restart_select_func();
  }

  /**
   * 左键 单击 全选
   * @param {MouseEvent} event
   * @returns
   */
  quick_func_select_all_click(event) {
    if (
      !event_check_func.cur_event(event).left_click().is_itself().checked_result
    ) {
      return;
    }
    this.select_all_func();
  }
}

export { select_node_operate };
